﻿@using Moonglade.Utils
@model CustomMenuSettings

@if (Model.IsEnabled && Model.Menus.Length > 0)
{
    foreach (var menuModel in Model.Menus.OrderBy(m => m.DisplayOrder))
    {
        if (menuModel.SubMenus.Count == 0)
        {
            <li class="nav-item">
                <a href="@Helper.SterilizeLink(menuModel.Url)"
                   class="nav-link"
                   target="@(menuModel.IsOpenInNewTab ? "_blank" : null)">
                    <span class="@menuModel.Icon d-lg-none d-xl-inline-block"></span>
                    <strong>@menuModel.Title</strong>
                </a>
            </li>
        }
        else
        {
            <li class="nav-item dropdown">
                <a href="#" class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown">
                    <span class="@menuModel.Icon d-lg-none d-xl-inline-block"></span>
                    <strong>@menuModel.Title</strong>
                </a>
                <ul class="dropdown-menu">
                    @foreach (var subMenu in menuModel.SubMenus.OrderBy(sm => sm.Title))
                    {
                        <li>
                            <a class="dropdown-item"
                               href="@Helper.SterilizeLink(subMenu.Url)"
                               target="@(subMenu.IsOpenInNewTab ? "_blank" : null)">
                                <span class="bi-link-45deg"></span>
                                @subMenu.Title
                            </a>
                        </li>
                    }
                </ul>
            </li>
        }
    }
}
